import  pandas as pd
# 求和 sum()

data = [
    [110,33,46],
    [133, 55, 91],
    [102, 76, 232]
]

index = [1,2,3]
columns = ['c','java','python']

df = pd.DataFrame(data=data,index=index,columns=columns)


df['总分'] = df.sum(axis=1) #  按行相加
# print(df)

# 求平均值
# new = df.mean()
# print(new)
# 最大值
# new = df.max()
# print(new)
# 最小值
# new = df.min()
# print(new)

# df = df._append(new,ignore_index=True)
# print(df)


# 中位数 median()
# print(df)
# print(df.median())



# 众数 mode()
# data = [[110,120,110] , [100,100,100] , [130,100,130]]
# data = [[110,120,110] , [130,130,130] , [130,120,130]]
#
# df = pd.DataFrame(data=data,index=index,columns=columns)
# print(df)
# print(df.mode())

# 方差 var()
data = [[110,113,103,105,108],[118,98,119,85,118]]
index = ['jack','rose']
columns = ['c1','c2','c3','c4','c5']
df = pd.DataFrame(data=data,index=index,columns=columns)

# print(df.var(axis=1))

# 任务::独立完成
# 标准差  std()
data = [[110,120,110] , [130,130,130] , [130,120,130]]
columns = ['java','python','c']
df = pd.DataFrame(data=data,columns=columns)

# print(df.std())

# 分位数 quantile()

data = [120,89,98,78,65,102,56,79,45]
columns = ['python']
df = pd.DataFrame(data=data,columns=columns)

#
# 计算35%分位数
x = df['python'].quantile(0.35)
# 输出淘汰的
# print(df[df['python'] <= x])


# 案例: 计算日期、时间和时间增量数据的分位数
#   A       B              C
#0  1    2019-01-01         1 days
#1  2    2020-01-01         2 days

pd.DataFrame({
    'A':[1,2],
    'B':[pd.Timestamp('2019'),pd.Timestamp('2020')],
    'C':[pd.Timedelta('1 days'),pd.Timedelta('2 days')]
})
#  提取年份 B列  年份
# df['B_year'] = df['B'].dt.year
# 计算 C列的总时间差
# total_timedelta = df['C'].sum

# numeric_only的默认值为False,表示对所以的行或列进行求和True则会对数字进行求和
# print(df.quantile(0.5,numeric_only=False))
print(df.quantile(0.5))







